﻿@model BestsellerBriefSearchModel
@using Nop.Services.Orders;

@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
@{
    const string panelId = "bestsellers-report-amount-box";
    const string hidePanelAttributeName = "Reports.HideBestsellersBriefReportByAmountPanel";
    var hidePanel = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hidePanelAttributeName);
}

<div class="box box-info @if(hidePanel){<text>collapsed-box</text>}" id="@panelId">
    <div class="box-header with-border">
        <h3 class="box-title">
            <i class="fa fa-star-o"></i>
            @T("Admin.Reports.Sales.BestSellers.ByAmount")
        </h3>
        <div class="box-tools pull-right">
            <button class="btn btn-box-tool" data-widget="collapse">
                @if (hidePanel)
                {
                    <text><i class="fa fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fa fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#@panelId').on('click', 'button[data-widget="collapse"]', function () {
                var collapsed = !$('#@panelId').hasClass('collapsed-box');
                saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hidePanelAttributeName', collapsed);
            });
        });
    </script>
    <div class="box-body">

        @await Html.PartialAsync("Table", new DataTablesModel
        {
           Name = "bestsellers-byamount-grid",
           UrlRead = new DataUrl("BestsellersBriefReportByAmountList", "Order", new RouteValueDictionary { [nameof(Model.OrderBy)] = OrderByEnum.OrderByTotalAmount }),
           Length = Model.PageSize,
           Dom = "<'row'<'col-md-12't>>" +
                      "<'row margin-t-5'" +
                        "<'col-lg-10 col-xs-12'<'float-lg-left'p>>" +
                        "<'col-lg-2 col-xs-12'<'float-lg-right text-center'i>>" +
                      ">",
           ColumnCollection = new List<ColumnProperty>
                {
                    new ColumnProperty(nameof(BestsellerModel.ProductName))
                    {
                        Title = T("Admin.Reports.Sales.Bestsellers.Fields.Name").Text
                    },
                    new ColumnProperty(nameof(BestsellerModel.TotalQuantity))
                    {
                        Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalQuantity").Text
                    },
                    new ColumnProperty(nameof(BestsellerModel.TotalAmount))
                    {
                        Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalAmount").Text
                    },
                    new ColumnProperty(nameof(BestsellerModel.ProductId))
                    {
                        Title = T("Admin.Common.View").Text,
                        Width = "50",
                        ClassName = NopColumnClassDefaults.Button,
                        Render = new RenderButtonView(new DataUrl("~/Admin/Product/Edit/"))
                    }
                }
       })
    </div>
</div>